package JZ;

import java.util.LinkedList;
import java.util.List;

public class jz8 {
    public static class TreeLinkNode {
        int val;
        TreeLinkNode left = null;
        TreeLinkNode right = null;
        TreeLinkNode next = null;

        TreeLinkNode(int val) {
            this.val = val;
        }
    }
    static List<TreeLinkNode> list = new LinkedList<>();
    public static void main(String[] args) {

    }
    public static TreeLinkNode GetNext(TreeLinkNode pNode) {
        TreeLinkNode t = pNode;
        while (t.next != null){
            t = t.next;
        }
        bl(t);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i) == pNode && i < list.size() - 1){
                return list.get(i + 1);
            }
        }
        return null;
    }
    public static void bl(TreeLinkNode p){
        if(p != null){
            bl(p.left);
            list.add(p);
            bl(p.right);
        }
    }
}
